package com.ruoyi.web.controller.dgw;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.RandomUtil;
import com.ruoyi.dgw.domain.Insurance;
import com.ruoyi.dgw.service.IInsuranceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保险Controller
 * 
 * @author ruoyi
 * @date 2021-11-18
 */
@RestController
@RequestMapping("/dgw/insurance")
@Api(tags = "保险相关接口")
public class InsuranceController extends BaseController
{
    @Autowired
    private IInsuranceService insuranceService;

    /**
     * 查询保险列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:insurance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Insurance insurance)
    {
        startPage();
        List<Insurance> list = insuranceService.selectInsuranceList(insurance);
        return getDataTable(list);
    }

    /**
     * 查询保险列表(审核通过的数据)
     */
    @PreAuthorize("@ss.hasPermi('dgw:insurance:selectList2')")
    @GetMapping("/selectList2")
    public TableDataInfo selectList2(Insurance insurance)
    {
        startPage();
        List<Insurance> list = insuranceService.selectList2(insurance);
        return getDataTable(list);
    }

    /**
     * 查询保险列表(未审核通过的数据)
     */
    @PreAuthorize("@ss.hasPermi('dgw:insurance:selectList1')")
    @GetMapping("/selectList1")
    public TableDataInfo selectList1(Insurance insurance){
        startPage();
        List<Insurance> list = insuranceService.selectList1(insurance);
        return getDataTable(list);
    }

    /**
     * 查询保险列表(驳回的数据)
     */
    @PreAuthorize("@ss.hasPermi('dgw:insurance:selectList3')")
    @GetMapping("/selectList3")
    public TableDataInfo selectList3(Insurance insurance){
        startPage();
        List<Insurance> list = insuranceService.selectList3(insurance);
        return getDataTable(list);
    }

    /**
     * 导出保险列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:insurance:export')")
    @Log(title = "保险", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Insurance insurance)
    {
        List<Insurance> list = insuranceService.selectInsuranceList(insurance);
        ExcelUtil<Insurance> util = new ExcelUtil<Insurance>(Insurance.class);
        return util.exportExcel(list, "保险数据");
    }

    /**
     * 获取保险详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dgw:insurance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(insuranceService.selectInsuranceById(id));
    }

    /**
     * 新增保险
     */
    @PreAuthorize("@ss.hasPermi('dgw:insurance:add')")
    @Log(title = "保险", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Insurance insurance)
    {
        return toAjax(insuranceService.insertInsurance(insurance));
    }

    /**
     * 修改保险
     */
    @PreAuthorize("@ss.hasPermi('dgw:insurance:edit')")
    @Log(title = "保险", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Insurance insurance)
    {
        return toAjax(insuranceService.updateInsurance(insurance));
    }

    /**
     * 删除保险
     */
    @PreAuthorize("@ss.hasPermi('dgw:insurance:remove')")
    @Log(title = "保险", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(insuranceService.deleteInsuranceByIds(ids));
    }


    /**
     * 新增保险
     */
    @Log(title = "保险", businessType = BusinessType.INSERT)
    @PostMapping("/insertInsuranceApp")
    @ApiOperation("保险购买")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "insureName", value = "投保人姓名", dataType = "String"),
            @ApiImplicitParam(name = "insureSfz", value = "投保人身份证", dataType = "String"),
            @ApiImplicitParam(name = "insureYhkh", value = "投保人银行卡号", dataType = "String"),
            @ApiImplicitParam(name = "insurePhone", value = "投保人手机号", dataType = "String"),
            @ApiImplicitParam(name = "beneficiaryName", value = "受益人姓名", dataType = "String"),
            @ApiImplicitParam(name = "beneficiarySfz", value = "受益人_身份证", dataType = "String"),
            @ApiImplicitParam(name = "beneficiaryYhkh", value = "受益人银行卡号", dataType = "String"),
            @ApiImplicitParam(name = "insuranceType", value = "险种名称", dataType = "String"),
            @ApiImplicitParam(name = "area", value = "所属区域", dataType = "String"),
            @ApiImplicitParam(name = "nickName", value = "养殖户名称", dataType = "String"),
            @ApiImplicitParam(name = "children", value = "耳标信息", dataType = "List"),
    })
    public AjaxResult insertInsuranceApp(@RequestBody Insurance insurance)
    {
        String data = DateUtils.dateTimeNow()+ RandomUtil.randomID();
        insurance.setInsuranceNumber("SXTB"+data);
        insurance.setPolicyNumber("SXBD"+ data);
        insurance.setReportNumber("SXBA"+ data);
        insurance.setRecordsNumber("SXBEA"+data);
        insuranceService.insertInsuranceApp(insurance);
        return AjaxResult.success("操作成功");
    }

}
